﻿using BCData.OA.TeamWorks.TaskRejectRecord;
using BCData.OA.TeamWorks.TaskRejectReplyRecord;
using BCDto.OA.TeamWorks.TaskRejectReplyRecord;
using BCEntity.OA.TeamWorks.TaskRecord;
using BCService.Utils;
using System;

namespace BCService.OA.TeamWorks.TaskRejectReplyRecord
{
    public class TaskRejectReplyRecordService : ITaskRejectReplyRecordService
    {
        private readonly IApplicationContextService applicationContextService;
        private readonly ITaskRejectReplyRecordData taskRejectReplyRecordData;
        private readonly ITaskRejectRecordData taskRejectRecordData;
        public TaskRejectReplyRecordService(IApplicationContextService applicationContextService,
            ITaskRejectReplyRecordData taskRejectReplyRecordData,
            ITaskRejectRecordData taskRejectRecordData)
        {
            this.applicationContextService = applicationContextService;
            this.taskRejectReplyRecordData = taskRejectReplyRecordData;
            this.taskRejectRecordData = taskRejectRecordData;
        }

        public TaskRejectReplyRecordDto Add(TaskRejectReplyRecordRequestDto requestDto)
        {

            if (!this.taskRejectRecordData.CheckExists(requestDto.WorkflowActivityInstanceId, requestDto.TaskRejectRecordId).GetAwaiter().GetResult())
            {
                throw new ArgumentException("驳回记录不存在");
            }
            TaskRejectReplyRecordEntity replyRecordEntity = requestDto.As<TaskRejectReplyRecordEntity>();
            replyRecordEntity.ReplyAdminId = applicationContextService.Admin.AdminId;
            replyRecordEntity.ReplyFullName = applicationContextService.Admin.FullName;
            replyRecordEntity.ReplyTime = DateTime.Now;
            return this.taskRejectReplyRecordData.Add(replyRecordEntity).GetAwaiter().GetResult().As<TaskRejectReplyRecordDto>();
        }

        //public TaskRejectReplyRecordDto Add(TaskRejectReplyRecordRequestDto requestDto)
        //{
        //    if (!this.taskRejectRecordData.CheckExists(requestDto.WorkflowActivityInstanceId, requestDto.TaskRejectRecordId).GetAwaiter().GetResult())
        //    {
        //        throw new ArgumentException("驳回记录不存在");
        //    }
        //    TaskRejectReplyRecordEntity replyRecordEntity = requestDto.As<TaskRejectReplyRecordEntity>();
        //    replyRecordEntity.ReplyAdminId = partnerExtendReference.UserId;
        //    replyRecordEntity.ReplyFullName = partnerExtendReference.UserName;
        //    replyRecordEntity.ReplyTime = DateTime.Now;
        //    return this.taskRejectReplyRecordData.Add(replyRecordEntity).GetAwaiter().GetResult().As<TaskRejectReplyRecordDto>();
        //}
    }
}
